package neu.edu.cn.nuemall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import neu.edu.cn.nuemall.entity.Comments;
import neu.edu.cn.nuemall.mapper.CommentsMapper;
import neu.edu.cn.nuemall.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentsServiceImpl implements CommentsService {
    @Autowired
    private CommentsMapper commentsMapper;
    @Override
    public PageInfo<Comments> getCommentsList(Integer page, Integer count, String user) {
        PageHelper.startPage(page,count);
        QueryWrapper<Comments> commentsWrapper=new QueryWrapper<Comments>();
        commentsWrapper.eq("name",user);
        List<Comments> commentsList=commentsMapper.selectList(commentsWrapper);
        PageInfo<Comments> commentsPageInfo=new PageInfo<Comments>(commentsList);

        return commentsPageInfo;
    }

    @Override
    public Comments getCommentsList(String id) {
        QueryWrapper<Comments> commentsWrapper = new QueryWrapper<Comments>();
        commentsWrapper.eq("books_no", id);

        Comments comments = commentsMapper.selectOne(commentsWrapper);

        return comments;
    }

    @Override
    public int delectCom(Comments comments) {
        int i=commentsMapper.deleteById(comments);
        return i;
    }

    @Override
    public int insertCom(Comments comments) {
        int i=commentsMapper.insert(comments);
        return i;
    }

}
